<template>
  <div>
    <el-dialog title="工序汇报单详情"  width="1100px" @open="open" class="icon-dialog" :visible.sync="show" :before-close="closeForm" append-to-body>
      <div>
        <el-button type="primary" size="small" icon="el-icon-check" @click="updateOptrpt()">修改</el-button>
      </div>
      <el-form ref="form" :model=" sfcOptrptform " size="small" label-width="80px" :inline="true" class="header">
        <el-row>
          <el-col :span="10">
            <el-form-item label="单据编号:" class="no-wrap-label">{{ sfcOptrptform.billNo }}</el-form-item>
          </el-col>
          <el-col :span="10">
            <el-form-item label="生产订单编号:" class="no-wrap-label" label-width="130px">{{ sfcOptrptform.moBillNo }}</el-form-item>
          </el-col>
          <el-col :span="10">
            <el-form-item label="单据日期:" class="no-wrap-label">{{ sfcOptrptform.createTime }}</el-form-item>
          </el-col>
          <el-col :span="10">
            <el-form-item label="汇报人:" class="no-wrap-label">{{ sfcOptrptform.createUserName }}</el-form-item>
          </el-col>
          <el-col :span="10">
            <el-form-item label="车间名称:" class="no-wrap-label">{{ sfcOptrptform.workShopName }}</el-form-item>
          </el-col>

          <el-col :span="10">
            <el-form-item label="件号:" class="no-wrap-label">{{ sfcOptrptform.specification }}</el-form-item>
          </el-col>
          <el-col :span="10">
            <el-form-item label="合格数量:" class="no-wrap-label">{{ sfcOptrptform.quaQty }}</el-form-item>
          </el-col>
          <el-col :span="10">
            <el-form-item label="报废数量:" class="no-wrap-label">{{ sfcOptrptform.failQty }}</el-form-item>
          </el-col>
          <el-col :span="10">

            <el-form-item label="外协不良:" class="no-wrap-label">
              <el-input
                v-model="sfcOptrptform.outFailQty"
                size="mini"
                placeholder="请输入外协不良"

            /></el-form-item>
          </el-col>
          <el-col :span="10">
            <el-form-item label="返修数量:" class="no-wrap-label">
              <el-input
                v-model="sfcOptrptform.returnQty"
                size="mini"
                placeholder="请输入返修数量"/>
            </el-form-item>
          </el-col>
        </el-row>

        <br />
      </el-form>




    </el-dialog>

  </div>
</template>
<script>
import { updatePackage  } from '@/api/app/sfcoptrpt'
export default {
  name:'sfcOptrptdetail',
  props: {
    show: {
      type: Boolean,
      default: true
    },
    size: {
      type: String,
      default: 'mini'
    },
    info: {
      type: Object,
    },
  },
  data() {
    return {
      sfcOptrptform:{}

    }
  },
  watch:{
    show(val){
      if(val){
      }
    }
  },
  methods: {
    //修改汇报详情
    updateOptrpt(){
      const outFail = Number(this.sfcOptrptform.outFailQty) || 0;
      const ret = Number(this.sfcOptrptform.returnQty) || 0;
      const fail = Number(this.sfcOptrptform.failQty) || 0;
      if (outFail + ret !== fail ){
        this.$message({
          type: 'warning',
          message: '无法保存，请确认外协不良 + 返修数量 = 废料数量'
        });
        return;
      }

      this.$confirm('是否确认修改', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        this.$message({
          type: 'success',
          message: '正在修改'
        });
        updatePackage( this.sfcOptrptform).then(res =>{
          if (res.data){
            this.$message({
              type: 'success',
              message: '修改成功!'
            });
            this.$emit('refresh_list'); // ✅ 通知父组件刷新
            this.closeForm()
          }
        })
      })
    },
    open(){
      this.sfcOptrptform = this.info
    },
    closeForm(){
      this.$emit('update:show', false)
    }
  }
}
</script>
<style  lang="scss">
@import '@/assets/scss/common.scss';
</style>
